#include <vector>
#include <unistd.h>
#include <string>
#include <iostream>
#include <memory>

class test {
public:
    test() {
        name_ = std::to_string(++index_);
        std::cout<<"class test"<< name_.c_str() << " construct" <<std::endl;
    }

    test(const test& other) {
        name_ = other.name_;
        std::cout<<"class test"<< name_.c_str() << " copy construct" <<std::endl;
    }

    test(const test&& other) {
        name_ = other.name_;
        std::cout<<"class test"<< name_.c_str() << " move construct" <<std::endl;
    }
    ~test() {
        std::cout<<"class test"<< name_.c_str() << " destruct" <<std::endl;
    }

private:
    static int index_;
    std::string name_;
};

int test::index_;

/*int main(int argc, const char **argv) {*/

    //std::vector<test> xx;
    ////test test1;
    //test test2;

    ////xx.emplace_back();
    ////xx.emplace_back(test2);
    ////xx.push_back((test2));
    //xx.push_back(std::move(test2));
    //std::cout<<"---------------------"<<std::endl;
    //sleep(3);
    //return 0;
/*}*/
int main(int argc, const char **argv) {
    std::string str = "Hello";
    std::vector<std::string> v;
    //调用常规的拷贝构造函数，新建字符数组，拷贝数据
    v.push_back(str);
    std::cout << "After copy, str is \"" << str << "\"\n";
    //调用移动构造函数，掏空str，掏空后，最好不要使用str
    //auto a = (std::move(str));
    v.push_back(std::move(str));
    std::cout << "After move, str is \"" << str << "\"\n";
    std::cout << "The contents of the vector are \"" << v[0]
                                         << "\", \"" << v[1] << "\"\n";

    auto ptr1 = std::make_unique<test>();
    auto ptr2 = std::move(ptr1);
    if (ptr1)
        std::cout<<"xxxxxxxxxxxxxxxxxxxxxx"<<std::endl;
    return 0;
}
